﻿#region Đào Mạnh Hòa
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace GUI.SoQuy
{
    public partial class frmSoQuy : Form
    {
        #region Cap nhap giao diện main
        public delegate void GetBoolean(Boolean capnhat);
        public GetBoolean GetData;
        #endregion

        #region Khởi tạo
        bool checkClose = false;
        public string month;
        public string year;

        public static string a = "0";
        DateTime date;
        Entities.SelectSoQuy temp;
        Entities.SoQuy[] hienthi;
        Entities.SoQuy[] soquy;
        Entities.SoDuSoQuy[] sodu;
        Entities.SoQuy save;
        string makho = "";
        string tenkho = "";
        double phatsinhno = 0;
        double phatsinhco = 0;
        double sdck = 0;
        double sddk = 0;
        DateTime batdau;
        DateTime ketthuc;
        int i = 0;

        public frmSoQuy()
        {
            InitializeComponent();
            Entities.CaiDatKho kho = Entitystatic.ViewFile();
            makho = kho.MaKho;
            tenkho = kho.TenKho;
            date = Entitystatic.date;
            cbbNam.Text = date.Year.ToString();
            cbbThang.Text = date.Month.ToString();
            month = cbbThang.Text;
            year = cbbNam.Text;

            if (cbbNam.Text != "")
            {
                if (cbbThang.Text != "")
                {
                    batdau = DateTime.Parse(cbbThang.Text + "/01/" + cbbNam.Text);
                    if (cbbThang.Text == "12")
                        ketthuc = DateTime.Parse("01/01/" + (Convert.ToInt32(cbbNam.Text) + 1).ToString());
                    else
                        ketthuc = DateTime.Parse((Convert.ToInt32(cbbThang.Text) + 1).ToString() + "/01/" + cbbNam.Text);

                    lblTieuDe.Text = "Sổ Quỹ từ ngày " + batdau.ToString("dd/MM/yyyy") + " đến ngày " + ketthuc.ToString("dd/MM/yyyy");
                    temp = Common.StaticVariable.InterfaceObject.SelectSSoQuy(makho);
                    sodu = temp.SoDuSoQuy;
                    HienThiTongThe();
                }
            }
        }

        public frmSoQuy(string nam, string thang)
        {
            try
            {
                InitializeComponent();
                date = Entitystatic.date;
                cbbNam.Text = date.Year.ToString();
                cbbThang.Text = date.Month.ToString();
                month = thang;
                year = nam;

                temp = Common.StaticVariable.InterfaceObject.SelectSSoQuy(makho);
                sodu = temp.SoDuSoQuy;
                HienThiTongThe();
            }
            catch
            {
            }
        }

        void fix()
        {
            for (int i = 0; i < dgvHienThi.ColumnCount; i++)
            {
                dgvHienThi.Columns[i].Visible = false;
            }
            dgvHienThi.ReadOnly = true;
            dgvHienThi.Columns[Common.Constants.SoQuy.MaTK].Visible = true;
            dgvHienThi.Columns[Common.Constants.SoQuy.TenTK].Visible = true;
            dgvHienThi.Columns[Common.Constants.SoQuy.SoDuDauKy].Visible = true;
            dgvHienThi.Columns[Common.Constants.SoQuy.PhatSinhNo].Visible = true;
            dgvHienThi.Columns[Common.Constants.SoQuy.PhatSinhCo].Visible = true;
            dgvHienThi.Columns[Common.Constants.SoQuy.SoDuCuoiKy].Visible = true;
            dgvHienThi.Columns[Common.Constants.SoQuy.MaTK].HeaderText = "Mã Tải Khoản";
            dgvHienThi.Columns[Common.Constants.SoQuy.TenTK].HeaderText = "Tên Tài Khoản";
            dgvHienThi.Columns[Common.Constants.SoQuy.SoDuDauKy].HeaderText = "Số Dư Đầu Kỳ";
            dgvHienThi.Columns[Common.Constants.SoQuy.PhatSinhNo].HeaderText = "Phát Sinh Nợ";
            dgvHienThi.Columns[Common.Constants.SoQuy.PhatSinhCo].HeaderText = "Phát Sinh Có";
            dgvHienThi.Columns[Common.Constants.SoQuy.SoDuCuoiKy].HeaderText = "Số Dư Cuối Kỳ";
            dgvHienThi.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvHienThi.AllowUserToAddRows = false;
            dgvHienThi.AllowUserToDeleteRows = false;
            dgvHienThi.AllowUserToResizeRows = false;
            dgvHienThi.RowHeadersVisible = false;
        }
        #endregion

        #region hiển thị
        void HienThiTongThe()
        {
            try
            {
                phatsinhno = phatsinhco = sdck = sddk = 0;
                hienthi = new Entities.SoQuy[temp.PhieuThu.Length + temp.PhieuChi.Length + temp.PhieuTTCuaKH.Length + temp.PhieuTTNCC.Length + 1];
                foreach (Entities.SoDuSoQuy item in sodu)
                {
                    string monthsodu = item.NgayKetChuyen.Month.ToString();
                    string yearsodu = item.NgayKetChuyen.Year.ToString();
                    if (month == monthsodu && year == yearsodu)
                    {
                        sddk = Convert.ToDouble(item.SoDuDauKy);
                        break;
                    }
                }
                int soluong = 0;

                //phiếu thu
                foreach (Entities.PhieuThu item in temp.PhieuThu)
                {
                    string month1 = item.NgayLap.Month.ToString();
                    string year1 = item.NgayLap.Year.ToString();
                    if (item.MaKho == makho && month == month1 && year == year1)
                    {
                        phatsinhno = Convert.ToDouble(item.TongTienThanhToan);
                        string ngaylap = Common.Utilities.XuLy(2, item.NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy();
                        hienthi[soluong].NgayLap = ngaylap;
                        hienthi[soluong].MaPhieu = item.MaPhieuThu;
                        hienthi[soluong].MaTK = "1111";
                        hienthi[soluong].TenTK = "Tiền mặt việt nam";
                        hienthi[soluong].PhatSinhNo = Format(phatsinhno);
                        hienthi[soluong].PhatSinhCo = Format(phatsinhco);
                        hienthi[soluong].DienGiai = item.GhiChu;
                        hienthi[soluong].TruongNgam = "PhieuThu";
                        soluong++;
                    }
                }

                phatsinhno = phatsinhco = 0;
                // Phiếu Chi
                foreach (Entities.PhieuChi item in temp.PhieuChi)
                {
                    string month1 = item.NgayLap.Month.ToString();
                    string year1 = item.NgayLap.Year.ToString();
                    if (item.MaKho == makho && month == month1 && year == year1)
                    {
                        phatsinhco = Convert.ToDouble(item.TongTienThanhToan);
                        string ngaylap = Common.Utilities.XuLy(2, item.NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy();
                        hienthi[soluong].NgayLap = ngaylap;
                        hienthi[soluong].MaPhieu = item.MaPhieuChi;
                        hienthi[soluong].MaTK = "1111";
                        hienthi[soluong].TenTK = "Tiền mặt việt nam";
                        hienthi[soluong].PhatSinhNo = Format(phatsinhno);
                        hienthi[soluong].PhatSinhCo = Format(phatsinhco);
                        hienthi[soluong].DienGiai = item.GhiChu;
                        hienthi[soluong].TruongNgam = "PhieuChi";
                        soluong++;
                    }
                }

                phatsinhno = phatsinhco = 0;
                // phiếu thanh toán khách hàng
                foreach (Entities.PhieuTTCuaKH item in temp.PhieuTTCuaKH)
                {
                    string month1 = item.NgayLap.Month.ToString();
                    string year1 = item.NgayLap.Year.ToString();
                    double a1 = double.Parse(item.TongThanhToan);
                    if (item.MaKho == makho && month == month1 && year == year1)
                    {
                        phatsinhco = phatsinhno = 0;
                        if (!item.LoaiPhieu)
                            phatsinhno = a1;
                        else
                            phatsinhco = a1;
                        string ngaylap = Common.Utilities.XuLy(2, item.NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy();
                        hienthi[soluong].NgayLap = ngaylap;
                        hienthi[soluong].MaPhieu = item.MaPhieuTTCuaKH;
                        hienthi[soluong].MaTK = "1111";
                        hienthi[soluong].TenTK = "Tiền mặt việt nam";
                        hienthi[soluong].PhatSinhNo = Format(phatsinhno);
                        hienthi[soluong].PhatSinhCo = Format(phatsinhco);
                        hienthi[soluong].DienGiai = item.GhiChu;
                        hienthi[soluong].TruongNgam = "PTTKH";
                        soluong++;
                    }
                }
                phatsinhco = phatsinhno = 0;
                // phiếu thanh toán nhà cung cấp
                foreach (Entities.PhieuTTNCC item in temp.PhieuTTNCC)
                {
                    string month1 = item.NgayLap.Month.ToString();
                    string year1 = item.NgayLap.Year.ToString();
                    double a1 = double.Parse(item.TongThanhToan);
                    if (item.MaKho == makho && month == month1 && year == year1)
                    {
                        phatsinhco = phatsinhno = 0;
                        if (item.LoaiPhieu)
                            phatsinhco = a1;
                        else
                            phatsinhno = a1;
                        string ngaylap = Common.Utilities.XuLy(2, item.NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy();
                        hienthi[soluong].NgayLap = ngaylap;
                        hienthi[soluong].MaPhieu = item.MaPhieuTTNCC;
                        hienthi[soluong].MaTK = "1111";
                        hienthi[soluong].TenTK = "Tiền mặt việt nam";
                        hienthi[soluong].PhatSinhNo = Format(phatsinhno);
                        hienthi[soluong].PhatSinhCo = Format(phatsinhco);
                        hienthi[soluong].DienGiai = item.GhiChu;
                        hienthi[soluong].TruongNgam = "PTTNCC";
                        soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                ArrayList array = new ArrayList();
                foreach (Entities.SoQuy item in hienthi)
                {
                    if (item != null)
                        array.Add(item);
                }
                array.Add(null);
                hienthi = (Entities.SoQuy[])array.ToArray(typeof(Entities.SoQuy));
                //Tính toán
                if (hienthi.Length == 1)
                {
                    soquy = new Entities.SoQuy[1];
                    soquy[0] = new Entities.SoQuy();
                    soquy[0].TenTK = "Tổng Cộng";
                    soquy[0].SoDuDauKy = Format(sddk);
                    soquy[0].PhatSinhNo = "0";
                    soquy[0].PhatSinhCo = "0";
                    soquy[0].SoDuCuoiKy = Format(sdck);
                }
                else
                {
                    soquy = new Entities.SoQuy[2];
                    for (int i = 0; i < hienthi.Length - 1; i++)
                    {
                        if (hienthi[i] != null)
                        {
                            phatsinhco += Convert.ToDouble(hienthi[i].PhatSinhCo);
                            phatsinhno += Convert.ToDouble(hienthi[i].PhatSinhNo);
                            sdck = sddk + phatsinhno - phatsinhco;
                            soquy[0] = new Entities.SoQuy();
                            soquy[0].MaTK = "1111";
                            soquy[0].TenTK = "Tiền mặt việt nam";
                            soquy[0].SoDuDauKy = Format(sddk);
                            soquy[0].PhatSinhNo = Format(phatsinhno);
                            soquy[0].PhatSinhCo = Format(phatsinhco);
                            soquy[0].SoDuCuoiKy = Format(sdck);
                            soquy[0].TruongNgam = "TongHop";
                        }
                    }

                    sdck = sddk + phatsinhno - phatsinhco;
                    soquy[1] = new Entities.SoQuy();
                    soquy[1].PhatSinhNo = Format(phatsinhno);
                    soquy[1].PhatSinhCo = Format(phatsinhco);
                    soquy[1].SoDuDauKy = Format(sddk);
                    soquy[1].TenTK = "Tổng Cộng";
                    soquy[1].SoDuCuoiKy = Format(sdck);
                    a = soquy[1].SoDuCuoiKy;
                }
                dgvHienThi.DataSource = soquy;
                fix();
            }
            catch
            {
            }
        }
        #endregion

        #region Format
        void HienThiTheoLoc()
        {
            try
            {
                phatsinhno = phatsinhco = sdck = sddk = 0;
                hienthi = new Entities.SoQuy[temp.PhieuThu.Length + temp.PhieuChi.Length + temp.PhieuTTCuaKH.Length + temp.PhieuTTNCC.Length + 1];
                int soluong = 0;
                foreach (Entities.SoDuSoQuy item in sodu)
                {
                    string monthsodu = item.NgayKetChuyen.Month.ToString();
                    string yearsodu = item.NgayKetChuyen.Year.ToString();
                    if (batdau.Month.ToString() == monthsodu && batdau.Year.ToString() == yearsodu)
                    {
                        sddk = Convert.ToDouble(item.SoDuDauKy);
                        break;
                    }
                }
                //phiếu thu
                foreach (Entities.PhieuThu item in temp.PhieuThu)
                {
                    if (item.MaKho == makho && item.NgayLap.Date >= batdau.Date && item.NgayLap.Date <= ketthuc.Date)
                    {
                        phatsinhno = Convert.ToDouble(item.TongTienThanhToan);
                        string ngaylap = Common.Utilities.XuLy(2, item.NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy();
                        hienthi[soluong].NgayLap = ngaylap;
                        hienthi[soluong].MaPhieu = item.MaPhieuThu;
                        hienthi[soluong].MaTK = "1111";
                        hienthi[soluong].TenTK = "Tiền mặt việt nam";
                        hienthi[soluong].PhatSinhNo = Format(phatsinhno);
                        hienthi[soluong].PhatSinhCo = Format(phatsinhco);
                        hienthi[soluong].DienGiai = item.GhiChu;
                        hienthi[soluong].TruongNgam = "PhieuThu";
                        soluong++;
                    }
                }

                phatsinhno = phatsinhco = 0;
                // Phiếu Chi
                foreach (Entities.PhieuChi item in temp.PhieuChi)
                {
                    if (item.MaKho == makho && item.NgayLap.Date >= batdau.Date && item.NgayLap.Date <= ketthuc.Date)
                    {
                        phatsinhco = Convert.ToDouble(item.TongTienThanhToan);
                        string ngaylap = Common.Utilities.XuLy(2, item.NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy();
                        hienthi[soluong].NgayLap = ngaylap;
                        hienthi[soluong].MaPhieu = item.MaPhieuChi;
                        hienthi[soluong].MaTK = "1111";
                        hienthi[soluong].TenTK = "Tiền mặt việt nam";
                        hienthi[soluong].PhatSinhNo = Format(phatsinhno);
                        hienthi[soluong].PhatSinhCo = Format(phatsinhco);
                        hienthi[soluong].DienGiai = item.GhiChu;
                        hienthi[soluong].TruongNgam = "PhieuChi"; soluong++;
                    }
                }

                phatsinhno = phatsinhco = 0;
                // phiếu thanh toán khách hàng
                foreach (Entities.PhieuTTCuaKH item in temp.PhieuTTCuaKH)
                {
                    double a1 = double.Parse(item.TongThanhToan);
                    if (item.MaKho == makho && item.NgayLap.Date >= batdau.Date && item.NgayLap.Date <= ketthuc.Date)
                    {
                        phatsinhco = phatsinhno = 0;
                        if (!item.LoaiPhieu)
                            phatsinhno = a1;
                        else
                            phatsinhco = a1;
                        string ngaylap = Common.Utilities.XuLy(2, item.NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy();
                        hienthi[soluong].NgayLap = ngaylap;
                        hienthi[soluong].MaPhieu = item.MaPhieuTTCuaKH;
                        hienthi[soluong].MaTK = "1111";
                        hienthi[soluong].TenTK = "Tiền mặt việt nam";
                        hienthi[soluong].PhatSinhNo = Format(phatsinhno);
                        hienthi[soluong].PhatSinhCo = Format(phatsinhco);
                        hienthi[soluong].DienGiai = item.GhiChu;
                        hienthi[soluong].TruongNgam = "PTTKH"; soluong++;
                    }
                }
                phatsinhco = phatsinhno = 0;
                // phiếu thanh toán nhà cung cấp
                foreach (Entities.PhieuTTNCC item in temp.PhieuTTNCC)
                {
                    double a1 = double.Parse(item.TongThanhToan);
                    if (item.MaKho == makho && item.NgayLap.Date >= batdau.Date && item.NgayLap.Date <= ketthuc.Date)
                    {
                        phatsinhco = phatsinhno = 0;
                        if (!item.LoaiPhieu)
                            phatsinhno = a1;
                        else
                            phatsinhco = a1;
                        string ngaylap = Common.Utilities.XuLy(2, item.NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy();
                        hienthi[soluong].NgayLap = ngaylap;
                        hienthi[soluong].MaPhieu = item.MaPhieuTTNCC;
                        hienthi[soluong].MaTK = "1111";
                        hienthi[soluong].TenTK = "Tiền mặt việt nam";
                        hienthi[soluong].PhatSinhNo = Format(phatsinhno);
                        hienthi[soluong].PhatSinhCo = Format(phatsinhco);
                        hienthi[soluong].DienGiai = item.GhiChu;
                        hienthi[soluong].TruongNgam = "PTTNCC"; soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                ArrayList array = new ArrayList();
                foreach (Entities.SoQuy item in hienthi)
                {
                    if (item != null)
                        array.Add(item);
                }
                array.Add(null);
                hienthi = (Entities.SoQuy[])array.ToArray(typeof(Entities.SoQuy));
                //Tính toán
                if (hienthi.Length == 1)
                {
                    soquy = new Entities.SoQuy[1];
                    soquy[0] = new Entities.SoQuy();
                    soquy[0].TenTK = "Tổng Cộng";
                    soquy[0].SoDuDauKy = Format(sddk);
                    soquy[0].PhatSinhNo = "0";
                    soquy[0].PhatSinhCo = "0";
                    soquy[0].SoDuCuoiKy = Format(sdck);
                }
                else
                {
                    soquy = new Entities.SoQuy[2];
                    for (int i = 0; i < hienthi.Length - 1; i++)
                    {
                        if (hienthi[i] != null)
                        {
                            phatsinhco += Convert.ToDouble(hienthi[i].PhatSinhCo);
                            phatsinhno += Convert.ToDouble(hienthi[i].PhatSinhNo);
                            sdck = sddk + phatsinhno - phatsinhco;
                            soquy[0] = new Entities.SoQuy();
                            soquy[0].MaTK = "1111";
                            soquy[0].TenTK = "Tiền mặt việt nam";
                            soquy[0].SoDuDauKy = Format(sddk);
                            soquy[0].PhatSinhNo = Format(phatsinhno);
                            soquy[0].PhatSinhCo = Format(phatsinhco);
                            soquy[0].SoDuCuoiKy = Format(sdck);
                            soquy[0].TruongNgam = "TongHop";
                        }
                    }
                    sdck = sddk + phatsinhno - phatsinhco;
                    soquy[1] = new Entities.SoQuy();
                    soquy[1].PhatSinhNo = Format(phatsinhno);
                    soquy[1].PhatSinhCo = Format(phatsinhco);
                    soquy[1].SoDuDauKy = Format(sddk);
                    soquy[1].TenTK = "Tổng Cộng";
                    soquy[1].SoDuCuoiKy = Format(sdck);
                    a = soquy[1].SoDuCuoiKy;
                }
                dgvHienThi.DataSource = soquy;
                fix();
            }
            catch
            {
            }
        }

        /// <summary>
        /// định dạng dữ liệu
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public string Format(double a)
        {
            if (a >= 0 && a < 10)
                return a.ToString();
            if (a < 0)
                return String.Format("{0,-0:0,0}", a);
            else
                return String.Format("{0:0,0}", a);
        }
        #endregion

        #region chi tiết giao dịch
        void ChiTietGiaoDich()
        {
            if (save == null)
            {
                return;
            }
            try
            {
                if (save.MaTK != null)
                {
                    frmChiTiet frm = new frmChiTiet(hienthi, temp, save.SoDuDauKy, save.SoDuCuoiKy);
                    frm.ShowDialog();
                }
            }
            catch
            {
            }
        }
        #endregion

        #region lọc điều kiện
        void LocDieuKien()
        {
            try
            {
                GUI.LocDieuKien.frmLocDieuKien frm = new LocDieuKien.frmLocDieuKien();
                frm.ShowDialog();
                if (GUI.LocDieuKien.frmLocDieuKien.kiemtra)
                {
                    DateTime truoc1;
                    DateTime sau1;
                    try
                    {
                        truoc1 = DateTime.Parse(GUI.LocDieuKien.frmLocDieuKien.truoc);
                        sau1 = DateTime.Parse(GUI.LocDieuKien.frmLocDieuKien.sau);
                    }
                    catch
                    {
                        return;
                    }
                    batdau = truoc1;
                    ketthuc = sau1;
                    HienThiTheoLoc();
                    lblTieuDe.Text = "Sổ Quỹ từ ngày " + batdau.ToString("dd/MM/yyyy") + " đến ngày " + ketthuc.ToString("dd/MM/yyyy");
                    GUI.LocDieuKien.frmLocDieuKien.kiemtra = false;
                }

            }
            catch
            {
            }
        }
        #endregion

        #region Thoát
        void Thoat()
        {
            this.Close();
        }
        #endregion

        #region Event
        private void frmSoQuy_Load(object sender, EventArgs e)
        {
            try
            {
                dgvHienThi.CellClick += new DataGridViewCellEventHandler(dgvHienThi_CellClick);
                dgvHienThi.CellDoubleClick += new DataGridViewCellEventHandler(dgvHienThi_CellDoubleClick);
                dgvHienThi.KeyDown += new KeyEventHandler(dgvHienThi_KeyDown);
                btnChiTiet.Click += new EventHandler(btnChiTiet_Click);
                btnThoat.Click += new EventHandler(btnThoat_Click);
                this.FormClosing += new FormClosingEventHandler(frmCongNo_FormClosing);
            }
            catch
            {
            }
        }

        void cbb_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                month = cbbThang.Text;
                year = cbbNam.Text;
                if (cbbNam.Text != "")
                {
                    if (cbbThang.Text != "")
                    {
                        lblTieuDe.Text = "Sổ Quỹ từ ngày " + batdau.ToString("dd/MM/yyyy") + " đến ngày " + ketthuc.ToString("dd/MM/yyyy");
                        temp = Common.StaticVariable.InterfaceObject.SelectSSoQuy(makho);
                        sodu = temp.SoDuSoQuy;
                        HienThiTongThe();
                    }
                }
            }
            catch { }
        }

        void btnChiTiet_Click(object sender, EventArgs e)
        {
            ChiTietGiaoDich();
        }

        void dgvHienThi_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                ChiTietGiaoDich();
            }
        }

        void dgvHienThi_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            ChiTietGiaoDich();
        }

        void dgvHienThi_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            i = e.RowIndex;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Thoat();
        }

        private void frmCongNo_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!checkClose)
                if (MessageBox.Show(Common.MSG.MSG2(), Common.MSG.TieuDe, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    e.Cancel = checkClose;
                else
                    e.Cancel = !checkClose;
        }
        #endregion

        private void btnLocDieuKien_Click(object sender, EventArgs e)
        {
            LocDieuKien();
        }

        private void dgvHienThi_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == hienthi.Length - 1)
            {
                return;
            }
            if (e.RowIndex >= 0)
            {
                save = ((Entities.SoQuy[])dgvHienThi.DataSource)[e.RowIndex];
            }
        }
    }
}
#endregion